package yznu_Bean_handle;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.RequestDispatcher;

import Goods_Utils.Good;
import User_Utils.User;
import yznu_jdbc.JDpoor;
import yznu_utils.Store;

public class infoUpdate {

	boolean f = false;
	Connection con = new JDpoor().CreateCon();;
	Statement sql = null;
	PreparedStatement pre = null;
	ResultSet rs = null;
	

	public boolean goodUpdate(Good good) {
		// TODO Auto-generated method stub
		String condition = "update goods_info set type=?,price=?,url=?,stock=? where name=?";
		try {
			pre = con.prepareStatement(condition);
			pre.setString(5, good.getName());
			pre.setString(1, good.getType());
			pre.setString(2, good.getPrice());
			pre.setString(3, good.getUrl());
			pre.setString(4, good.getStock());
			int t = pre.executeUpdate();
	    	if(t!=0)
	    		f = true;
	    	else
	    		f = false;
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println(e);
		}
		return f;
	}



	public boolean userUpdate(User user) {
		// TODO Auto-generated method stub
		String condition = "update user_info set phone=?,email=?,password=? where name=?";
		try {
			pre = con.prepareStatement(condition);
			pre.setString(1, user.getPhone());
			pre.setString(2, user.getEmail());
			pre.setString(3, user.getPassword());
			pre.setString(4, user.getName());
			int t = pre.executeUpdate();
	    	if(t!=0)
	    		f = true;
	    	else
	    		f = false;
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println(e);
		}
		return f;
	}


	public boolean storeUpdate(Store store) {
		// TODO Auto-generated method stub
		String condition = "update otherStore_info set phone=?,address=?,boss=? where name=?";
		try {
			pre = con.prepareStatement(condition);
			pre.setString(1, store.getPhone());
			pre.setString(2, store.getAddress());
			pre.setString(3, store.getBoss());
			pre.setString(4, store.getName());
			int t = pre.executeUpdate();
	    	if(t!=0)
	    		f = true;
	    	else
	    		f = false;
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println(e);
		}
		return f;
	}
	
	
	
}
